<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var NestedIterator = function (nestedList) {
            vals = nestedList
            while (vals.some(Array.isArray)) {
                vals = [].concat(...vals);
            }
        };
        NestedIterator( [[1,1],2,[1,1]])
        console.log(vals)

        /**
         * @this NestedIterator
         * @returns {boolean}
         */
        NestedIterator.prototype.hasNext = function () {
            return vals.length > 0;
        };

        /**
         * @this NestedIterator
         * @returns {integer}
         */
        NestedIterator.prototype.next = function () {
            const val = vals[0];
            vals = vals.slice(1);
            return val;
        };
    </script>
</body>

</html>